Skip to content

Offload blocking wallet calls to spawn_blocking#18

Merged
amackillop merged 1 commit intolsp-0.7.0from
austin_spawn-blocking-wallet-traversals
Apr 15, 2026
Merged

Offload blocking wallet calls to spawn_blocking#18
amackillop merged 1 commit intolsp-0.7.0from
austin_spawn-blocking-wallet-traversals

Conversation

@amackillop
Copy link
Copy Markdown

BDK wallet operations (apply_update, create_funding_transaction, get_spendable_amount_sats) internally acquire a mutex and walk the checkpoint chain, giving O(T*C) runtime where T is the number of transactions and C is the number of checkpoints. Running these on a tokio worker thread blocks the entire async executor during sync-heavy workloads.

Move these calls to spawn_blocking so they run on the tokio blocking threadpool instead. This is a stopgap until BDK lands their height-indexed checkpoint work upstream.

JoinError (panic or runtime shutdown) is mapped into the existing error paths at each call site: WalletOperationFailed for esplora sync and funding tx creation, unwrap_or(0) for spendable balance checks (conservative default that skips channel opens).

BDK wallet operations (apply_update, create_funding_transaction,
get_spendable_amount_sats) internally acquire a mutex and walk
the checkpoint chain, giving O(T*C) runtime where T is the
number of transactions and C is the number of checkpoints.
Running these on a tokio worker thread blocks the entire async
executor during sync-heavy workloads.

Move these calls to spawn_blocking so they run on the tokio
blocking threadpool instead. This is a stopgap until the underlying
issue is addressed in BDK.

JoinError (panic or runtime shutdown) is mapped into the
existing error paths at each call site: WalletOperationFailed
for esplora sync and funding tx creation, unwrap_or(0) for
spendable balance checks (conservative default that skips
channel opens).
@amackillop amackillop merged commit 08393ee into lsp-0.7.0 Apr 15, 2026
6 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant